<?php
declare (strict_types = 1);

namespace app\model;

use Carbon\Carbon;

/**
 * @property mixed $params
 * @property integer $order_id
 * @property integer $type
 * @property integer $pay_method
 */
class Notify extends BaseModel
{
    public $autoWriteTimestamp = false;
    protected $field = [
        'order_id','params','created_at','type','pay_method'
    ];
    protected $json = ['params'];
    protected $jsonAssoc = true;
    const TYPE_SEND = 0;
    const TYPE_CREATE_DRAFT = 1;//创建草稿订单
    const TYPE_MODIFY_DRAFT = 2;//修改草稿订单
    const TYPE_PLACE_ORDER = 3;//下单
    const TYPE_CHECKOUT = 4;//重定向
    const TYPE_CAPTURE_ORDER = 5;//支付
    const TYPE_REPURCHASE = 6;//加购
    const TYPE_CAPTURE_PURCHASE = 7;//支付加购
    const TYPE_NOTIFY = 8;//异步通知
    const TYPE_COMPLETE_DRAFT = 9;//完成草稿订单
    const TYPE_UPDATE_ORDER = 10;//更新订单
    const TYPE_DRAFT_REPURCHASE = 11;//草稿加购
    const TYPE_DRAFT_QUICK_PAY  = 12;//快捷草稿
    const TYPE_SHIPPING_ZONE = 13;//运费接口
    const TYPE_PAYPAL_DETAIL = 14;
    const TYPE_QUICK_PAY_AND_CREATE_ORDER = 15;
    const TYPE_PAYPAL_GOOGLE_AND_APPLE_PAY = 16;


    public static function saveParams($order_id,$params,$type = self::TYPE_SEND,$pay_method = 0)
    {
        if(empty($params)) return null;
        return self::create(['order_id'=>$order_id,'params'=>$params,'type'=>$type,'created_at'=>Carbon::now()->toDateTimeString(),'pay_method'=>$pay_method]);
    }


    //创建订单日志
    public static function saveLogs($params,$type)
    {
        return self::create([
            'params'=>$params,
            'type'=>$type,
            'created_at'=>Carbon::now()->toDateTimeString(),
        ]);
    }

}
